#include"List.h"

void TestStack1()
{
	ST st;
	StackInit(&st);
	StackPush(&st, 1);
	StackPush(&st, 2);
	StackPush(&st, 3);
	StackPush(&st, 4);
	StackPush(&st, 5);
	StackDestroy(&st);

}

bool isValid(char* s) {
    ST st;
    StackInit(&st);
    while (*s)
    {
        if (*s == '[' || *s == '{' || *s == '(')
        {
            StackPush(&st, *s);
            ++s;
        }
        else
        {
            if (StackEmpty(&st))
            {
                StackDestroy(&st);
                return false;
            }
            char top = StackTop(&st);
            StackPop(&st);
            if ((*s == ']' && top != '[')
                || (*s == '}' && top != '{')
                || (*s == ')' && top != '('))
            {
                StackDestroy(&st);
                return false;
            }
            else
            {
                ++s;
            }
        }

    }
    bool ret = StackEmpty(&st);
    return ret;
}

int main()
{
    //TestStack1();
    char s[] = "()";
    isValid(s);
	return 0;
}
